package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevPlanRuleAmDao;
import com.sugon.entity.DevAmRulesEntity;
import com.sugon.entity.DevPlanRuleAmEntity;
import com.sugon.service.DevPlanRuleAmService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 设备维护计划与规程关联配置表Service实现类
 *
 * @author YuXD
 * @date 2023-01-30
 */
@Service("devPlanRuleAmService")
public class DevPlanRuleAmServiceImpl implements DevPlanRuleAmService {

    @Autowired
    private DevPlanRuleAmDao devPlanRuleAmDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevPlanRuleAmEntity queryObject(String id) {
        return devPlanRuleAmDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevPlanRuleAmEntity> queryList(Map<String, Object> map) {
        return devPlanRuleAmDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devPlanRuleAmDao.queryTotal(map);
    }

    /**
     * queryRelatedRuleList
     *
     * @param map
     * @return
     */
    @Override
    public List<DevAmRulesEntity> queryRelatedRuleList(Map<String, Object> map) {
        return devPlanRuleAmDao.queryRelatedRuleList(map);
    }

    /**
     * queryRelatedRuleTotal
     *
     * @param map
     * @return
     */
    @Override
    public int queryRelatedRuleTotal(Map<String, Object> map) {
        return devPlanRuleAmDao.queryRelatedRuleTotal(map);
    }

    /**
     * save
     *
     * @param devPlanRule 实体
     * @return
     */
    @Override
    public int save(DevPlanRuleAmEntity devPlanRule) {
        devPlanRule.setId(RandomUtil.randomString(32));
        devPlanRule.setCreatorId(ShiroUtils.getUserId());
        devPlanRule.setCreateDate(DateUtil.date());
        return devPlanRuleAmDao.save(devPlanRule);
    }

    /**
     * update
     *
     * @param devPlanRule 实体
     * @return
     */
    @Override
    public int update(DevPlanRuleAmEntity devPlanRule) {
        return devPlanRuleAmDao.update(devPlanRule);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devPlanRuleAmDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devPlanRuleAmDao.deleteBatch(ids);
    }

    /**
     * 查看维护计划和维护规程是否已建立关联
     *
     * @param planId 维护计划ID
     * @param ruleId 维护规程ID
     * @return
     */
    @Override
    public boolean checkIsExists(String planId, String ruleId) {
        Map<String, Object> map = new HashMap<>(2);
        map.put("planId", planId);
        map.put("ruleId", ruleId);
        return devPlanRuleAmDao.queryTotal(map) > 0;
    }

    @Override
    public List<DevPlanRuleAmEntity> list(String planId, String ruleId) {
        Map<String, Object> map = new HashMap<>(2);
        map.put("planId", planId);
        map.put("ruleId", ruleId);
        return devPlanRuleAmDao.queryList(map);
    }

}
